﻿using System;
using System.Collections.Generic;
using System.Web;
using AspNetInfo.Core;
using System.Data;

namespace AspNetInfo.Detectors
{
    public class AspNetDetector : IDetector
    {
        public DataTable Detect(EnvironmentPermissions permissions)
        {
            var dt = DetectorHelper.MakeResultTable();
            dt.Rows.Add("Trust Level", Enum.GetName(typeof(AspNetHostingPermissionLevel), permissions.TrustLevel));
            dt.Rows.Add("Web App Path", HttpContext.Current.Server.MapPath("~/"));
            

            if (permissions.TrustLevel > AspNetHostingPermissionLevel.Medium)
            {
                dt.Rows.Add("ClrInstallDirectory", HttpRuntime.ClrInstallDirectory);
                dt.Rows.Add("App Domain Id", HttpRuntime.AppDomainAppId);
                dt.Rows.Add("AppDomainAppPath", HttpRuntime.AppDomainAppPath);
                dt.Rows.Add("AppDomainAppVirtualPath", HttpRuntime.AppDomainAppVirtualPath);
                dt.Rows.Add("AppDomainId", HttpRuntime.AppDomainId);
                dt.Rows.Add("AspClientScriptPhysicalPath", HttpRuntime.AspClientScriptPhysicalPath);
                dt.Rows.Add("AspClientScriptVirtualPath", HttpRuntime.AspClientScriptVirtualPath);
                dt.Rows.Add("AspInstallDirectory", HttpRuntime.AspInstallDirectory);
                dt.Rows.Add("BinDirectory", HttpRuntime.BinDirectory);
                dt.Rows.Add("CodegenDir", HttpRuntime.CodegenDir);
                dt.Rows.Add("IsOnUNCShare", HttpRuntime.IsOnUNCShare.ToString());
                dt.Rows.Add("MachineConfigurationDirectory", HttpRuntime.MachineConfigurationDirectory);
            }
            return dt;
        }

        public string Name
        {
            get { return "ASP.NET"; }
        }

        public string Description
        {
            get { return string.Empty; }
        }

        public string TabName
        {
            get { return Tabs.AspNet; }
        }
    }
}
